home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / rdcf.exe / DOSFILES.DOC < prev    next >
Text File  |  1993-01-15  |  27KB  |  560 lines

  1.                      A Description of the DOS File System
  2.  
  3.                             by Philip J. Erdelsky
  4.                           PLAIN VANILLA CORPORATION
  5.                             CompuServe 75746,3411
  6.                       InterNet 75746.3411@compuserve.com
  7.  
  8.                                January 15, 1993
  9.  
  10.                  Copyright (c) 1993 Plain Vanilla Corporation
  11.  
  12.  
  13. 1. Introduction
  14. ---------------
  15.  
  16. The DOS file system is used not only by IBM PC's and compatibles, but also by
  17. some standalone word processors that use diskettes and by a number of other
  18. devices. Even computer systems that normally use a different file system, such
  19. as UNIX-based workstations, also have the ability to read and write diskettes
  20. in DOS format. All of these uses together make the DOS file system the single
  21. most widely used file system in the world.
  22.  
  23. The file system has evolved a great deal since its origin in DOS 1.0. The
  24. version described here is essentially that used by DOS 3.3. The large
  25. partitions used by DOS 4.0 and later versions of DOS are not included.
  26.  
  27. This description was written in conjunction with version 2.0 of the Plain
  28. Vanilla Reentrant DOS-Compatible File System, an implementation of the basic
  29. DOS file system written in portable C and distributed as free software.
  30.  
  31. There are a number of details regarding the DOS file system that are
  32. undocumented. Some of them have been filled in by experimentation; others are
  33. simply described as undefined;
  34.  
  35. 2. Block Devices
  36. ----------------
  37.  
  38. A DOS file system resides on what is generally called a block device.  This is
  39. usually a disk of some kind, but it may also be a part of regular or extended
  40. memory that has been configured as a RAM disk.
  41.  
  42. A block device stores information in sectors of equal size.  The most common
  43. sector size is 512 bytes, which is used by all standard DOS floppy diskettes,
  44. but some RAM disks and hard disks may use sectors containing 128, 256 or 1024
  45. bytes.
  46.  
  47. The sectors are numbered in a very simple way.  Each sector has a logical sector
  48. number.  The smallest logical sector number is zero, and the largest logical
  49. sector number is one less than the number of sectors.  Every logical sector
  50. number between these limits is assigned to one other sector.  There are no gaps
  51. in the numbering system.
  52.  
  53.  
  54. 3. Mapping Sides and Tracks
  55. ---------------------------
  56.  
  57. The logical sector numbering system usually hides some complexities that must
  58. be handled by the disk controller hardware, the disk driver software or both.
  59. The sectors on a disk are arranged into concentric circles called tracks.  Most
  60. floppy disks have tracks on both sides.  A hard disk has more than two sides,
  61. because it consists of two or more disks, rotating in unison on the same
  62. spindle.
  63.  
  64. Some disk controllers, especially hard disk controllers, accept logical sector
  65. numbers and make all conversions internally; but this is not always the case.
  66.  
  67. To read or write a sector, the disk controller first moves a reading and
  68. writing device, called a head, back or forth until it is positioned over the
  69. track containing the desired sector.  If the disk has tracks on more than one
  70. side, there is head for each side of the disk, and they move together.  The
  71. disk controller selects the proper head by electronic switching.  Finally, the
  72. disk controller waits until the disk rotation brings the desired sector under
  73. the head.  Then it reads or writes the sector.
  74.  
  75. To convert a logical sector number L into the corresponding side, track and
  76. sector numbers, the controller (or the software driver) usually needs the
  77. following three numbers:
  78.  
  79.      N = the number of sectors per track,
  80.      T = the number of tracks per side, and
  81.      S = the number of sides.
  82.  
  83. The tracks are usually numbered from 0 to T-1, with track 0 on the outside and
  84. track T-1 on the inside.  This puts the most frequently accessed sectors (those
  85. with low logical sector numbers) on the outside of the disk, where sectors are
  86. largest and the disk is the most reliable.
  87.  
  88. The sides are usually numbered from 0 to S-1, in an order determined by the
  89. hardware design.
  90.  
  91. The sectors in a single track are numbered from 1 to N, where the disk rotation
  92. carries them under a head in order of increasing sector number.  The numbering
  93. starts with 1, not 0.  The reason for this odd convention is not clear, but it
  94. is followed by a number of floppy disk drives, including the ones usually used
  95. with DOS-based computers.
  96.  
  97. The assignment of logical sector numbers to sectors on a disk follows a simple
  98. scheme with a straightforward object -- to minimize access time when the
  99. sectors are read or written in order of ascending logical sector numbers.  This
  100. usually means minimizing the number of times the heads must be moved, since
  101. this is by far the slowest kind of disk operation.
  102.  
  103. The formulas are as follows, where A rem B means the remainder when A is
  104. divided by B:
  105.  
  106.     sector number = L rem N + 1
  107.     side number = (L/N) rem S
  108.     track number = (L/N) / S
  109.  
  110. Logical sector number 0 is sector 1 in track 0 on side 0.  Since this sector
  111. can always be located without knowing the disk structure, it is often used to
  112. store information about the disk structure. This is important for floppy disks,
  113. which are removable.  Many floppy disk drives can accommodate disks with more
  114. than one format.  The file system codecan read logical sector 0 to find out
  115. how to locate other sectors.
  116.  
  117. As the logical sector number increases, the heads must be moved only when the
  118. track number increases.  This does not happen until all sectors with a
  119. particular track number have been accessed.
  120.  
  121. The number of tracks is needed only to check the track number to see whether it
  122. is in range.  This is advisable in some cases because some disk drives may be
  123. damaged if an attempt is made to move the heads beyond their normal range.
  124.  
  125.  
  126. 4. Handling Bad Sectors
  127. -----------------------
  128.  
  129. On any large hard disk, there are apt to be some bad spots.  Some hard disk
  130. controllers can remap the bad spots and make the disk appear to be a perfect
  131. disk with a slightly smaller capacity.  This is usually done during low-level
  132. formatting.
  133.  
  134. However, floppy disk controllers and some hard disk controllers cannot do this.
  135. To handle most cases of this kind, the DOS file system can be set up so that
  136. some sectors are marked as bad.  No DOS file information will be written into
  137. bad sectors.  This lowers the disk capacity, but it makes imperfect disks
  138. usable.  This is usually done when the disk is formatted.
  139.  
  140. If there is a bad sector in a critical area of the disk, such as the part that
  141. indicates which sectors are bad, the disk cannot be used to hold a DOS file
  142. system.  Fortunately, the critical area of a disk is quite small, so this is
  143. quite unlikely.
  144.  
  145.  
  146. 5. Disk Partitions
  147. ------------------
  148.  
  149. The original DOS file system used 16-bit logical sector numbers, so it could
  150. handle only file systems with at most 65535 sectors, or 32 megabytes when
  151. 512-byte sectors were used.  This was the infamous 32-megabyte barrier.  DOS
  152. could use a disk with more than 65535 sectors, but it could use only 65535
  153. sectors for its file system.
  154.  
  155. A simple solution to this problem is to divide the disk into two or more
  156. partitions, each of which contains no more than 65535 sectors, and to treat
  157. each partition as though it were a separate disk.
  158.  
  159. DOS 4.00 and later versions of DOS can use 32-bit logical sector numbers, so
  160. they can handle larger partitions.  This would seem to imply an 8-terabyte
  161. maximum, but other limitations make the practical maximum smaller than that.
  162.  
  163. This document covers only partitions of 32 megabytes or less that use 16-bit
  164. logical sector numbers.
  165.  
  166.  
  167. 6. The Layout of a DOS Disk
  168. ---------------------------
  169.  
  170. The sectors of a DOS disk are divided into the following groups, which are
  171. listed in order of increasing logical sector numbers:
  172.  
  173.      RESERVED SECTORS
  174.      FILE ALLOCATION TABLES
  175.      ROOT DIRECTORY
  176.      DATA AREA
  177.      HIDDEN SECTORS
  178.  
  179. The groups are described in detail in the following sections.
  180.  
  181.  
  182. 7. Reserved Sectors
  183. ------